package com.ming.netty.inoutboundhandler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class MyByteToLongDecoder extends ByteToMessageDecoder {
    /**
     *
     * @param channelHandlerContext 上下文对象
     * @param in 入站的ByteBuf
     * @param out  将解码后的数据传入下一个handler
     * @throws Exception
     */
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {

        System.out.println("MyByteToLongDecoder 调用");
        //因为Long 是八个字节
        if (in.readableBytes()>=8){
            out.add(in.readLong());
        }
    }
}
